package com.chzc.goods.controller.pub;

import com.chzc.goods.service.IGoodsService;
import com.chzc.po.Goods;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author cv大魔王
 * @version 1.0
 * @date 2021/5/27 17:24
 */
@Api(value = "秒杀商品接口(公共)", tags = "秒杀商品接口(公共)")
@RestController
@RequestMapping("/pub/goods")
public class PubGoodsController {

    @Autowired
    private IGoodsService goodsService;

    @ApiOperation("根据id查询商品")
    @GetMapping("/{id}")
    @ApiImplicitParam(name="id", value="菜单ID", required=true)
    public Goods findById(@PathVariable String id){
        return goodsService.findById(id);
    }

    @ApiOperation("今日秒杀")
    @GetMapping("/today/goods_list")
    public List<Goods> commoditiesOfTheDay(){
        return goodsService.commoditiesOfTheDay();
    }

    @ApiOperation("今日未开始秒杀列表")
    @GetMapping("/future/goods_list")
    public List<Goods> notYetStarted(){
        return goodsService.notYetStarted();
    }

    @ApiOperation("获取商品实时库存")
    @GetMapping("/real_time/stock/{goodsId}")
    @ApiImplicitParam(name = "goodsId", value = "商品ID", required = true)
    public Integer realTimeInventory(@PathVariable String goodsId) {
        return goodsService.realTimeInventory(goodsId);
    }

}
